-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No need to handle freelist as a specical case when freeing a page #788
Conversation
Signed-off-by: Benjamin Wang <[email protected]>
eaf4f1e
to
d1cd0de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. However, I'd suggest having @tjungblu review this PR, too :), as I'm not an expert on freelist.
@@ -67,9 +67,6 @@ func (t *shared) Free(txid common.Txid, p *common.Page) { | |||
allocTxid, ok := t.allocs[p.Id()] | |||
if ok { | |||
delete(t.allocs, p.Id()) | |||
} else if p.IsFreelistPage() { | |||
// Freelist is always allocated by prior tx. | |||
allocTxid = txid - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Line 79 txp.alloctx = append(txp.alloctx, allocTxid)
could append zero into alloctx.
There are two cases we should consider:
Rollback
The zero value will be covered by the rollback. So it looks fine.
bbolt/internal/freelist/shared.go
Lines 96 to 99 in efc3eb6
tx := txp.alloctx[i] | |
if tx == 0 { | |
continue | |
} |
Release by opening new writable TX
This change looks safe to me because the page will be free after all the read-only TX are closed.
I think the original Freelist is always allocated by prior tx.
might free the page which can be read by opening read-only TX.
bbolt/internal/freelist/shared.go
Lines 179 to 183 in efc3eb6
for i := 0; i < len(txp.ids); i++ { | |
if atx := txp.alloctx[i]; atx < begin || atx > end { | |
continue | |
} | |
m = append(m, txp.ids[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahrtr, fuweid, ivanvc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm Thanks @ahrtr - I'll adjust the testcases accordingly. |
Read #67 (comment)
When the page ID to be freed isn't included in
f.allocs
, then it means it must be allocated before opening the db this time, and the write transaction is the very first write TXN after opening the db. So it (the page ID to be freed) must be visible to all readonly transactions. We just need to use the default value 0 for such case, in the same way as we did for other page types.Will rebase this PR once #775 gets merged.
The existing test cases already cover the sanity test. We will add more dedicated test cases for freelist management later.
cc @tjungblu @fuweid @ivanvc